package com.android.panballgame;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class PBLoad extends Activity {
	final PBEngine engine = new PBEngine();	
	public static ImageButton load;
	public static Button delete; 
	public static TextView datano, datalevel, dataremain, datatime;
	private int btnflag = 0, re = 0, s = 0, m = 0;
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.load);
		
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//화면 꺼짐 방지

		load = (ImageButton) findViewById(R.id.btndata);
		datano = (TextView) findViewById(R.id.textdata1);
		datalevel = (TextView) findViewById(R.id.datalevel);
		dataremain = (TextView) findViewById(R.id.dataremain);
		datatime = (TextView) findViewById(R.id.datatime);

		load.getBackground().setAlpha(PBEngine.MENU_BUTTON_ALPHA);
		load.setHapticFeedbackEnabled(PBEngine.HAPTIC_BUTTON_FEEDBACK);

		if (PBMainMenu.check_record1(PBEngine.LEVEL_TABLE)) {
			datalevel.setVisibility(1);
			dataremain.setVisibility(1);
			datatime.setVisibility(1);
			PBMainMenu.db_getmain();
			PBMainMenu.db_getlevel2();
			re = PBEngine.remain;
			datalevel.setText("LEVEL : " + PBEngine.level);
			if(re<0)
				re = 0;
			dataremain.setText("남은 과제 수 : " + re);
		     s = (int) (PBEngine.time * -0.001);
		     if(s >= 60){
		    	 m = s/60;
		    	 s = s%60;
		    	 datatime.setText("TIME : " + m + "분 "+ s + "초");
		     }  	 
		     else
		    	 datatime.setText("TIME : " + s + "초");
			btnflag = 1;
		} else
			datano.setVisibility(1);

		load.setOnClickListener(new ImageButton.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (btnflag == 1) {
					PBEngine.useDb = 1;
					finish();
					PBMainMenu.db_getlevel();
					Intent game = new Intent(getApplicationContext(), PBGame.class);
					startActivity(game);
				} else
					;
			}
		});
	}	
}
